/***************************************************************************
                          StateMgr.hpp  -  description
                             -------------------
    begin                : October 29 2009
    copyright            : Copyright 2009, ACKERMANN Thibaut
    email                : tackerma@edu.univ-fcomte.fr
    website              : http://code.google.com/p/nover-project/
    license              : GNU GPL v3
 ***************************************************************************/
/* *************************************************************************
 *  This file is part of NOver-Project.
 *  
 *  NOver-Project is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *  
 *  NOver-Project is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with NOver-Project.  If not, see <http://www.gnu.org/licenses/>.
 * *************************************************************************/


#ifndef _STATEMGR_
#define _STATEMGR_

#include <vector>

#include <irrlicht.h>

#include "Singleton.hpp"
#include "GameState.hpp"
#include "MyException.hpp"
#include "EventReceiver.hpp"

using namespace std;
using namespace irr;

using gui::IGUIEnvironment;
using video::IVideoDriver;
using scene::ISceneManager;
using core::dimension2d;
using core::position2d;
using video::SColor;


/**
 * La classe StateMgr gere le passage entre les GameState
 * @sa PlayState
 * @author Thibaut Ackermann
 */
class StateMgr : public Singleton<StateMgr>
{
	friend class Singleton<StateMgr>;
	
public:
	
	/**
	 * Cette fonction permet de changer d'état (comme passer du MenuState au PlayState)
	 * l'état courant est sauvegardé (empiler)
	 * @param newState le nouvel état
	 */
	void pushState(GameState* newState);
	
	/**
	 * Cette fonction permet de repasser à l'état precedant
	 */
	void popState();
	
	/**
	 * Cette fonction lance le rendu (démarre le jeu)
	 */
	void startRender();
	
	
	IrrlichtDevice* getDevice()
	{
		return irrdevice;
	}
	
	ISceneManager* getSceneMgr()
	{
		return irrsmgr;
	}
	
	IGUIEnvironment* getGuiEnv()
	{
		return irrgui;
	}
	
	IVideoDriver* getDriver()
	{
		return irrdriver;
	}
	
	/**
	 * @return hauteur courante de la fenêtre
	 */
	int getWindowHeight()
	{
		return windowSize.Height;
	}
	
	/**
	 * @return largeur courante de la fenêtre
	 */
	int getWindowWidth()
	{
		return windowSize.Width;
	}
	
	EventReceiver* getEventReceiver()
	{
		return &myreceiver;
	}
	
	/**
	 * @return état en cours d'utilisation
	 */
	GameState* getCurrentGameState()
	{
		return states.back();
	}
	
	/**
	 * @return nombre d'états empilés (état en cours d'utilisation compris)
	 */
	int getGameStateCount()
	{
		return states.size();
	}
	
private:
	
	StateMgr() throw (MyException);
	
	~StateMgr();
	
	vector<GameState*> states;
	
	int windowHeight;
	int windowWidth;
	
	core::dimension2d<s32> windowSize;
	
	EventReceiver myreceiver;
	
	// irrlicht
	IrrlichtDevice* irrdevice;
	IVideoDriver* irrdriver;
	ISceneManager* irrsmgr;
	IGUIEnvironment* irrgui;
};

#endif

